package com.ydm.myapp001.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;


import com.ydm.myapp001.R;
import com.ydm.myapp001.bean.MyOkHttpCallBack;
import com.ydm.myapp001.bean.MyOkHttpUtil;
import com.ydm.myapp001.utils.AppLogger;

import java.util.HashMap;
import java.util.Map;


public class TestHttpActivity extends AppCompatActivity {
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_http);
        mContext = this;
    }


    public void btnClick(View v) {
        switch(v.getId()){
            case R.id.get_request: {
                Map<String, Object> oneMap =  new HashMap<>();
                oneMap.put("id", "106220716");
                //
                MyOkHttpUtil.getInstance().okHttpGet(this, "http://itunes.apple.com/cn/lookup?id=106220716", "get_request", oneMap, new MyOkHttpCallBack() {
                    @Override
                    public void onSuccess(String result) {
                        AppLogger.e("MySelf", "Activity中收到的onSuccess: \n" + result);
                    }

                    @Override
                    public void onError(String errorMsg) {
                        AppLogger.e("MySelf", "Activity中收到的onError: \n" + errorMsg);
                    }
                });
            }
                break;
            case R.id.post_request_wwwform: {
                Map<String, Object> oneMap =  new HashMap<>();
                oneMap.put("msg", "{\"method\":\"cashier.login\",\"appId\":\"rwmmoa1495442077210\",\"mobile\":\"13523448667\",\"password\":\"670b14728ad9902aecba32e22fa4f6bd\"}");
                oneMap.put("sign", "32ca20632061c9bdccc0f3fa330f1043");

                //
                MyOkHttpUtil.getInstance().okHttpPostByFormEncoding(this, "https://b.tingzhijun.com/v1/gateway.htm", "post_request_wwwform", oneMap, new MyOkHttpCallBack() {
                    @Override
                    public void onSuccess(String result) {
                        AppLogger.e("MySelf", "Activity中收到的onSuccess: \n" + result);
                    }

                    @Override
                    public void onError(String errorMsg) {
                        AppLogger.e("MySelf", "Activity中收到的onError: \n" + errorMsg);
                    }
                });
            }
                break;
            case R.id.post_request_json: {
                Map<String, Object> oneMap =  new HashMap<>();
                oneMap.put("userName", "tom");
                oneMap.put("pwd", "123456");

                //
                MyOkHttpUtil.getInstance().okHttpPostByJson(this, "http://47.105.183.249:8084/api/v1/userAccount/userLogin", "post_request_json", oneMap, new MyOkHttpCallBack() {
                    @Override
                    public void onSuccess(String result) {
                        AppLogger.e("MySelf", "Activity中收到的onSuccess: \n" + result);
                    }


                    @Override
                    public void onError(String errorMsg) {
                        AppLogger.e("MySelf", "Activity中收到的onError: \n" + errorMsg);
                    }
                });
            }
                break;
            case R.id.post_request_multiformData: {
                Map<String, Object> oneMap =  new HashMap<>();
                oneMap.put("msg", "{\"number\":\"S202191P70121\",\"timestamp\":\"1556520440091\",\"password\":\"111111\",\"appId\":\"rwmmoa1553670203097\",\"method\":\"cashier.login\",\"username\":\"13523448667\"}");
                oneMap.put("sign", "c36b79454928632e54d6a3f58ec74679");

                //
                MyOkHttpUtil.getInstance().okHttpPostByFormData(this, "http://cash.api.haiposoft.com/v1/gateway.jhtml", "post_request_multiformData", oneMap, new MyOkHttpCallBack() {
                    @Override
                    public void onSuccess(String result) {
                        AppLogger.e("MySelf", "Activity中收到的onSuccess: \n" + result);
                    }

                    @Override
                    public void onError(String errorMsg) {
                        AppLogger.e("MySelf", "Activity中收到的onError: \n" + errorMsg);
                    }
                });
            }
                break;
            default:
                break;
        }
    }























}
